package com.py.outbound.service.impl;

import java.util.List;

import com.py.outbound.domain.WhInventory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.py.outbound.mapper.WhOutboundDetailsMapper;
import com.py.outbound.domain.WhOutboundDetails;
import com.py.outbound.service.IWhOutboundDetailsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-23
 */
@Service
public class WhOutboundDetailsServiceImpl implements IWhOutboundDetailsService
{
    @Autowired
    private WhOutboundDetailsMapper whOutboundDetailsMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param detailsId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public WhOutboundDetails selectWhOutboundDetailsByDetailsId(Long detailsId)
    {
        return whOutboundDetailsMapper.selectWhOutboundDetailsByDetailsId(detailsId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param whOutboundDetails 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<WhOutboundDetails> selectWhOutboundDetailsList(WhOutboundDetails whOutboundDetails)
    {
        return whOutboundDetailsMapper.selectWhOutboundDetailsList(whOutboundDetails);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param whOutboundDetails 【请填写功能名称】
     * @return 结果
     */
    @Override
    @Transactional
    public int insertWhOutboundDetails(WhOutboundDetails whOutboundDetails)
    {   Integer result = whOutboundDetailsMapper.insertWhOutboundDetails(whOutboundDetails);
        if (result > 0){
            WhInventory whInventory = new WhInventory();
            whInventory.setLocationCode(whOutboundDetails.getLocationCode());
            whInventory.setProductCode(whOutboundDetails.getProductCode());
            whInventory.setPendingOut(Math.toIntExact(whOutboundDetails.getOutboundNumber()));
            System.out.println("数量");
            System.out.println(whInventory);
            whOutboundDetailsMapper.updatePendingOutNum(whInventory);
        }
        return result;
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param whOutboundDetails 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateWhOutboundDetails(WhOutboundDetails whOutboundDetails)
    {
        return whOutboundDetailsMapper.updateWhOutboundDetails(whOutboundDetails);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param outboundCodes 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteWhOutboundDetailsByDetailsIds(Long[] outboundCodes)
    {
        return whOutboundDetailsMapper.deleteWhOutboundDetailsByDetailsIds(outboundCodes);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param  【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteWhOutboundDetailsByDetailsId(String outboundCode)
    {
        return whOutboundDetailsMapper.deleteWhOutboundDetailsByDetailsId(outboundCode);
    }

    @Override
    public List<WhOutboundDetails> selectWhOutboundDetailsByOutBoundCode(String outboundCode) {
        return whOutboundDetailsMapper.selectWhOutboundDetailsByOutBoundCode(outboundCode);
    }
}

